package controller

import (
	"github.com/gin-gonic/gin"
	"log"
	"mouth-project/pkg"
	"net/http"
)

//文件上传

func Upload(c *gin.Context) {
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	dst := "\\Users\\14899\\Desktop\\t.jpg" + file.Filename
	// 上传文件至指定的完整文件路径
	err := c.SaveUploadedFile(file, dst)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"msg":  "文件上传失败",
			"code": 400,
			"err":  err.Error(),
		})
		return
	}
	pkg.Upload(dst, file.Filename)
	c.JSON(http.StatusOK, gin.H{
		"msg":  "文件上传成功",
		"code": 200,
		"file": file.Filename,
	})
}
